package org.jadestudio.home.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.ibatis.sqlmap.client.SqlMapClient;


public class GameDao {
	private SqlMapClient sqlMapClient;
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	
	/**
	 * 获取首页游戏列表
	 */
	public List<java.util.Map> getHomePageGameList() throws SQLException{
		return sqlMapClient.queryForList("game.getHomePageGameList");
	}
	
	/**
	 * 获取当月游戏发售表 
	 */
	public List<java.util.Map> getGameRetailList(int year,int month) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("year", year);
		map.put("month", month);
		return sqlMapClient.queryForList("game.getGameRetailList", map);
	}
	
	/**
	 * 获取游戏类型列表 
	 */
	public List<java.util.Map> getGameTypeList() throws SQLException{
		return sqlMapClient.queryForList("game.getGameTypeList");
	}
	
	/**
	 * 获取游戏平台列表 
	 */
	public List<java.util.Map> getGamePlatformList() throws SQLException{
		return sqlMapClient.queryForList("game.getGamePlatformList");
	}
	
	
	/*
	 * 游戏列表筛选
	 */
	public List<java.util.Map> getGameList(String category,String initial,String platform,int pageindex,int pagesize) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("category", category);
		map.put("initial", initial);
		map.put("platform", platform);
		map.put("startindex", (pageindex-1)*pagesize);
		map.put("endindex", pagesize);
		
		return sqlMapClient.queryForList("game.getGameList",map);
	}
	
	
	/*
	 * 获取游戏筛选列表总页数
	 */
	public int getGamePageCount(String category,String initial,String platform,int pagesize) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("category", category);
		map.put("initial", initial);
		map.put("platform", platform);
		map.put("pagesize", pagesize);
		
		Object result = sqlMapClient.queryForObject("game.getGamePageCount",map);
		return (Integer)result;
	}
	
	/*
	 * 获取指定搜索关键字游戏（前12个）
	 */
	public List<java.util.Map> searchGamesByKeyname(String keyname) throws SQLException{
		return sqlMapClient.queryForList("game.searchGamesByKeyname", keyname);
	}
	
	
	/*
	 * 获取游戏详情BYID
	 */
	public java.util.Map getGameDetail(String id) throws SQLException{
		return (java.util.Map)sqlMapClient.queryForObject("game.getGameDetail", id);
	}
	
	
	/*
	 * 获取游戏平台ID对应名称
	 */
	public List<java.util.Map> getGamePlatformById(String ids) throws SQLException{
		return sqlMapClient.queryForList("game.getGamePlatformById", ids);
	}
	
	
	/*
	 * 获取游戏截图列表
	 */
	public List<java.util.Map> getGameScreenshotList(String id) throws SQLException{
		return sqlMapClient.queryForList("game.getGameScreenshotList", id);
	}
	
	
	/*
	 * 获取类似游戏列表
	 */
	public List<java.util.Map> getSimilarGameList(String id,String tag) throws SQLException{
		String[] tags = tag.split(",");
		java.util.Map map = new java.util.HashMap();
		map.put("id", id);
		if (tags.length>0)
			map.put("tag1", tags[0]);
		else
			map.put("tag1", "");
		if (tags.length>1)
			map.put("tag2", tags[1]);
		else
			map.put("tag2", "");
		if (tags.length>2)
			map.put("tag3", tags[2]);
		else
			map.put("tag3", "");
		
		return sqlMapClient.queryForList("game.getSimilarGameList", map);
	}
	
		
	/*
	 * 获取游戏相关文章列表
	 */
	public List<java.util.Map> getGameArticleList(String id) throws SQLException{
		return sqlMapClient.queryForList("game.getGameArticleList", id);
	}
	
	
	/*
	 * 获取指定发行/开发厂商的游戏
	 */
	public List<java.util.Map> getGamesListByCompany(String id,String dev_company,String publish_company_id) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("id", id);
		map.put("dev_company", dev_company);
		map.put("publish_company_id", publish_company_id);
		return sqlMapClient.queryForList("game.getGamesListByCompany", map);
	}
	
	
	/*
	 * 获得游戏投票情况
	 */
	public List<java.util.Map> getGameVotes(String id,String ip) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("game_id", id);
		map.put("ip", ip);
		return sqlMapClient.queryForList("game.getGameVotes", map);
	}
	
	
	/*
	 * 游戏投票
	 */
	public int voteGame(String game_id,int score,String ip) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("game_id", game_id);
		map.put("score", score);
		map.put("ip", ip);
		
		int result = (Integer)sqlMapClient.queryForObject("game.voteGame", map);
		return result;
	}
	
	
	/*
	 * 获取游戏下载链接
	 */
	public List<java.util.Map> getGameDownloads(String id) throws SQLException{
		return sqlMapClient.queryForList("game.getGameDownloads", id);
	}
	
	
	/*
	 * 获取游戏购买链接
	 */
	public List<java.util.Map> getGamePurchases(String id) throws SQLException{
		return sqlMapClient.queryForList("game.getGamePurchases", id);
	}
}
